<template>
	<view class="bg-white flex flex-direction" style="height: 100vh;">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">
				<text>期刊</text>
			</block>
		</cu-custom>
		<!-- 专栏组件 -->
		<column class="flex-sub flex  flex-direction" :tablist="tablist" ref="column" @change="handleChange">
			<!-- 轮播展示 -->
			<swiper class="margin flex-sub" @change="onSwiperchange" :current="current">
				<swiper-item v-for="(item,num) in tablist" :key="num">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="loadMoreData">
						<view v-for="(journal,index) in journalList" :key="index" 
						@click="$Router.push({
							name:'journalIndex', 
							params: {
								journalId: journal.id,
								currentNumber: journal.number
							}
						})" >
							<journal-cell :journal="journal"></journal-cell>
						</view>
						<load-more v-if="journalList.length>5" :status="item.loadMoreStatus"></load-more>
					</scroll-view>
				</swiper-item>
			</swiper>
		</column>
	</view>
</template>

<script>
	import cuCustom from '../../plugin/colorui/components/cu-custom.vue'
	import column from '../../components/column/column.vue'
	import journalCell from '../../components/column/journalCell.vue'
	import loadMore from '../../components/mine/loadMore.vue';
	export default{
		components:{
			journalCell,
			column,
			loadMore
		},
		data() {
			return {
				page: 1,
				current: 0, //swiper当前滑块
				tablist: [],
				journalList: [],
			}
		},
		onLoad() {
			this.$http.get('/edu/onesubject/getAllOneSubject').then(res =>{
				this.tablist=res.data.result
				this.tablist.forEach(item =>{
					item.loadMoreStatus=0
					item.id="a"+item.id
				})
				// console.log(this.tablist)
			})
			this.$http.get('/edu/journal/getJournalColumnList').then((res) => {
					let data = res.data;
					if(data.success) {
						// console.log("success", data.result)
						this.journalList = data.result
					}else {
						console.log("data fail")
					}
				}).catch((err) => {
					console.log(err);
				})
		},
		methods: {
			loadMoreData() {
				console.log("test")
				this.tablist[this.current].loadMoreStatus = 1;
				// 更改加载页数
				this.page++;
		
				if (this.journalList.length < 15) {
					this.journalList = this.journalList.concat(this.journalList);
					this.tablist[this.current].loadMoreStatus = 0;
				} else {
					this.tablist[this.current].loadMoreStatus = 2;
					this.$forceUpdate()
				}
			},
			onSwiperchange(e) {
				this.$refs.column.switchtab(e.detail.current)
				this.current = e.detail.current
				this.tablist[this.current].loadMoreStatus = 0;
			},
			handleChange(index) {
				this.current = index
				this.tablist[this.current].loadMoreStatus = 0;
			}
		}
	}
</script>

<style>
</style>
